package com.leyou.user.dto;

import com.leyou.common.dto.BaseDTO;
import com.leyou.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotNull;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;


@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class UserRequestDTO extends BaseDTO {
    @NotNull(message = "用户名不能为空")
    @Length(min = 4,max = 30,message = "用户名长度在4-30之间")
    private String username;
    private String password;
    private String phone;
    private String code;


    public UserRequestDTO(BaseEntity entity) {
        super(entity);
    }

    public static <T extends BaseEntity> List<UserRequestDTO> convertEntityList(Collection<T> list) {
        if (list == null) {
            return Collections.emptyList();
        }
        return list.stream().map(UserRequestDTO::new).collect(Collectors.toList());
    }
}